﻿CREATE TABLE [dbo].[tbl_UserProfile] (
    [UserId]          BIGINT             NOT NULL,
	[UserName]       NVARCHAR (128)  NULL,
    [Created]         DATETIME        NULL,
    [LastActivity]   DATETIME        NULL,
    [Description]     NVARCHAR (500)  NULL,
    [Photo]           NVARCHAR(500) NULL,
    [IsPro]          TINYINT         NOT NULL DEFAULT 0,
    [ProExpired]     DATETIME        NULL,
    [CellPhone1]     NVARCHAR (30)   NULL,
    [CellPhone2]     NVARCHAR (256)   NULL,
    
    [WorkForm] TINYINT NOT NULL DEFAULT 0, 
    CONSTRAINT [PK_tbl_UserProfile] PRIMARY KEY CLUSTERED ([UserId] ASC),
    CONSTRAINT [FK_tbl_UserProfile_tbl_Users] FOREIGN KEY ([UserId]) REFERENCES [dbo].[tbl_Users] ([Id])
);


GO

CREATE TRIGGER [dbo].[Trigger_tbl_UserProfile]
    ON [dbo].[tbl_UserProfile]
    FOR  INSERT, UPDATE
    AS
    BEGIN
        SET NoCount ON
		UPDATE tbl_UserProfile SET [LastActivity]=GETDATE()
		FROM inserted WHERE inserted.UserId=tbl_UserProfile.UserId
    END